﻿namespace com.crownpack.export
{
    using System;

    using com.crownpack.ExportConfigurationDao;
    using com.crownpack.SharePoint;

    public class FullExportManager : ExportManager
    {
        #region Constructors

        public FullExportManager( )
            : this(string.Empty)
        {
        }

        public FullExportManager( string currentWebUrl )
        {
            CurrentWebUrl = currentWebUrl;
            ExportConfigurationDao dao = string.IsNullOrEmpty( CurrentWebUrl ) ? new ExportConfigurationDao( ) : new ExportConfigurationDao( getRootWebUrl( ) );
            Configuration = dao.GetActiveFullExport( );
        }

        #endregion Constructors

        #region Methods

        public bool Export( )
        {
            bool ok = true;
            foreach ( ExportConfiguration config in Configuration )
            {
                DateTime? currentExport = null;
                bool k = FullExportToDocumentLibrary(config, out currentExport );
                ok = ok && k;
                if ( k )
                {
                    UpdateLastExport( currentExport, config );
                }
                else
                {
                    CustomLoggingService.LogWarning( CustomLoggingService.Area.TimerJob, "Full export of {0} to {1} ended in error.", config.ListUrl, config.DocumentLibraryUrl );
                }
            }
            return ok;
        }

        #endregion Methods
    }
}